package com.sqlparser.util;

import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause;
import com.alibaba.druid.sql.dialect.hive.ast.HiveInsertStatement;
import com.alibaba.druid.sql.dialect.hive.parser.HiveStatementParser;
import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.sql.parser.SQLParserUtils;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import com.sqlparser.dto.DataLineageDto;
import net.sf.jsqlparser.statement.select.WithItem;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DruidSqlUtil {

    public static List<DataLineageDto> createParser(String sql) {
        List<DataLineageDto> list = new ArrayList<>();
        try {
            // 使用通用的 SQL 解析器
           // List<SQLStatement> hive = SQLUtils.parseStatements(sql, "hive");
            SQLStatementParser parser = new HiveStatementParser(sql);
            SQLStatement stmt = parser.parseStatement();
            if (stmt instanceof HiveInsertStatement) {
                list = createParser((HiveInsertStatement) stmt);
            }
            System.out.println("SQL语句解析成功：" + stmt.toString());
        } catch (ParserException e) {
            System.err.println("解析Hive SQL语句时出错：" + e.getMessage());
            e.printStackTrace();
        }

        return list;
    }

    public static List<DataLineageDto> createParser(HiveInsertStatement stmt) {
        List<DataLineageDto> list = new ArrayList<>();
        SQLExprTableSource tableSource = stmt.getTableSource();
        SQLExpr expr = tableSource.getExpr();
        SQLSelect query = stmt.getQuery();
        List<SQLAssignItem> partitions = stmt.getPartitions();
        List<Map<String, String>> list1 = new ArrayList<>();
        if (partitions != null && partitions.size() > 0) {
            for (SQLAssignItem item : partitions) {
                Map<String, String> map = new HashMap<>(2);
                String key = item.getTarget().toString();
                String value = item.getValue().toString();
                map.put("columnName", key);
                map.put("aliasName", value);
                list1.add(map);
            }
        }
        String tableName = null;
        if (expr instanceof SQLName) {
            tableName = ((SQLName) expr).getSimpleName();
        }
        SQLWithSubqueryClause with = stmt.getWith();
        if (with != null) {
            // List<WithItem> withItemsList = with.get();
            // SqlParserUtil.getWithItem(withItemsList, list);
            List<SQLWithSubqueryClause.Entry> entries = with.getEntries();
            for (SQLWithSubqueryClause.Entry entry : entries) {
                String name = entry.getAlias().toString();
                String sql = entry.getSubQuery().toString();
                String alias = entry.getAlias();
                list.addAll(SqlParserUtil.parseViewDefinition(sql));
            }
        }
        DataLineageDto dataLineageDto = new DataLineageDto();
        dataLineageDto.setSourceTable(tableName);
        dataLineageDto.setType("INSERT");
        dataLineageDto.setColumnItems(list1);
        list.add(dataLineageDto);
        if (query != null) {
            SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(query.toString(), "hive");
            List<SQLStatement> stmts = parser.parseStatementList();
            for (SQLStatement stmt1 : stmts) {
                list.addAll(SqlParserUtil.parseViewDefinition(stmt1.toString()));
            }
        }

        return list;
    }

    public static void main(String[] args) {
        String viewSql = "WITH MES_RELEASE_ROUTE AS \n" +
                "  (\n" +
                "         --获取ERP中基于MES_SO发放的指令,包含FO、AO\n" +
                "         --JJERP\n" +
                "         SELECT ROW_NUMBER() OVER( PARTITION BY ms.ID order by MSRL.creation_date DESC) AS R_NUM,\n" +
                "                'JJERP'                AS datasource,\n" +
                "                MS.ID                  AS MES_ID,\n" +
                "                MS.FO_NO               AS FO_NO,\n" +
                "                'FO'                   AS ROUTE_TYPE,\n" +
                "                TR_F.Routid            AS Routid,\n" +
                "                TR_F.PRTNO             AS PRTNO,\n" +
                "                TR_F.ROUTNO            AS ROUTNO,\n" +
                "                TR_F.PRTMDEPT          AS PRTMDEPT,\n" +
                "                MS.CREATION_DATE       AS MES_CREATION_DATE\n" +
                "           FROM XAC_ERP.ODS_JJERP_MES_SO MS\n" +
                "     INNER JOIN XAC_ERP.ODS_JJERP_MDS_ITEM MI ON MI.ID = MS.MDS_ITEM_ID\n" +
                "     INNER JOIN XAC_ERP.ODS_JJERP_Mes_So_Release_List MSRL ON MSRL.MES_SO_ID = MS.ID\n" +
                "     INNER JOIN XAC_ERP.ODS_JJERP_T_ROUTVERSION TR_F ON TR_F.ROUTID = MSRL.LEANMES_ROUTID\n" +
                "          WHERE TR_F.ROUTID IS NOT NULL\n" +
                "            AND TR_F.ORDERTYPE = 'FO'   \n" +
                "     UNION\n" +
                "         SELECT ROW_NUMBER() OVER(PARTITION BY MS.ID,TR_AL.PRTNO,TR_AO.PRTNO order by MSRL.CREATION_DATE DESC) AS R_NUM,\n" +
                "                'JJERP'                                  AS datasource,\n" +
                "                MS.ID                                    AS MES_ID,\n" +
                "                MS.FO_NO                                 AS FO_NO,\n" +
                "                'AO'                                     AS ROUTE_TYPE,\n" +
                "                coalesce(TR_AL.Routid, TR_AO.Routid)     AS Routid,\n" +
                "                coalesce(TR_AL.PRTNO, TR_AO.PRTNO)       AS PRTNO,\n" +
                "                coalesce(TR_AL.ROUTNO, TR_AO.ROUTNO)     AS ROUTNO,\n" +
                "                coalesce(TR_AL.PRTMDEPT, TR_AO.PRTMDEPT) AS PRTMDEPT,\n" +
                "                MS.CREATION_DATE                         AS MES_CREATION_DATE\n" +
                "           FROM XAC_ERP.ODS_JJERP_MES_SO MS\n" +
                "     INNER JOIN XAC_ERP.ODS_JJERP_MDS_ITEM MI ON MI.ID = MS.MDS_ITEM_ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_JJERP_Mes_So_Release_List MSRL ON MSRL.MES_SO_ID = MS.ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_JJERP_T_AOLIST AO_L ON AO_L.ID = MSRL.LEANMES_ROUTID\n" +
                "      LEFT JOIN XAC_ERP.ODS_JJERP_T_AOLISTITEM AO_LI ON AO_LI.AOLISTID = AO_L.ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_JJERP_T_ROUTVERSION TR_AL ON TR_AL.ROUTID = AO_LI.ROUTID\n" +
                "      LEFT JOIN XAC_ERP.ODS_JJERP_T_ROUTVERSION TR_AO ON TR_AO.ROUTID = MSRL.LEANMES_ROUTID\n" +
                "          WHERE (TR_AL.ROUTID IS NOT NULL OR TR_AO.ROUTID IS NOT NULL)\n" +
                "            AND (TR_AL.ORDERTYPE = 'AO' OR TR_AO.ORDERTYPE = 'AO')\n" +
                "   \n" +
                "         UNION\n" +
                "         --民机 \n" +
                "         SELECT ROW_NUMBER() OVER(PARTITION BY ms.ID order by MSRL.creatION_date DESC ) AS R_NUM,\n" +
                "                'MJERP'                AS datasource,\n" +
                "                MS.ID                  AS MES_ID,\n" +
                "                MS.FO_NO               AS FO_NO,\n" +
                "                'FO'                   AS ROUTE_TYPE,\n" +
                "                TR_F.Routid            AS Routid,\n" +
                "                TR_F.PRTNO             AS PRTNO,\n" +
                "                TR_F.ROUTNO            AS ROUTNO,\n" +
                "                TR_F.PRTMDEPT          AS PRTMDEPT,\n" +
                "                MS.CREATION_DATE       AS MES_CREATION_DATE\n" +
                "           FROM XAC_ERP.ODS_MJERP_MES_SO MS\n" +
                "     INNER JOIN XAC_ERP.ODS_MJERP_MDS_ITEM MI ON MI.ID = MS.MDS_ITEM_ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_MJERP_Mes_So_Release_List MSRL ON MSRL.MES_SO_ID = MS.ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_MJERP_T_ROUTVERSION TR_F ON TR_F.ROUTID = MSRL.LEANMES_ROUTID\n" +
                "          WHERE TR_F.ROUTID IS NOT NULL\n" +
                "            AND TR_F.ORDERTYPE = 'FO'\n" +
                "         UNION\n" +
                "         SELECT ROW_NUMBER() OVER(PARTITION BY MS.ID,TR_AL.PRTNO,TR_AO.PRTNO order by MSRL.CREATION_DATE DESC) AS R_NUM,\n" +
                "                'MJERP' AS datasource,\n" +
                "                MS.ID                                    AS MES_ID,\n" +
                "                MS.FO_NO                                 AS FO_NO,\n" +
                "                'AO'                                     AS ROUTE_TYPE,\n" +
                "                coalesce(TR_AL.Routid, TR_AO.Routid)     AS Routid,\n" +
                "                coalesce(TR_AL.PRTNO, TR_AO.PRTNO)       AS PRTNO,\n" +
                "                coalesce(TR_AL.ROUTNO, TR_AO.ROUTNO)     AS ROUTNO,\n" +
                "                coalesce(TR_AL.PRTMDEPT, TR_AO.PRTMDEPT) AS PRTMDEPT,\n" +
                "                MS.CREATION_DATE                         AS MES_CREATION_DATE\n" +
                "           FROM XAC_ERP.ODS_MJERP_MES_SO MS\n" +
                "     INNER JOIN XAC_ERP.ODS_MJERP_MDS_ITEM MI ON MI.ID = MS.MDS_ITEM_ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_MJERP_Mes_So_Release_List MSRL ON MSRL.MES_SO_ID = MS.ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_MJERP_T_AOLIST AO_L ON AO_L.ID = MSRL.LEANMES_ROUTID\n" +
                "      LEFT JOIN XAC_ERP.ODS_MJERP_T_AOLISTITEM AO_LI ON AO_LI.AOLISTID = AO_L.ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_MJERP_T_ROUTVERSION TR_AL ON TR_AL.ROUTID = AO_LI.ROUTID\n" +
                "      LEFT JOIN XAC_ERP.ODS_MJERP_T_ROUTVERSION TR_AO ON TR_AO.ROUTID = MSRL.LEANMES_ROUTID\n" +
                "          WHERE (TR_AL.ROUTID IS NOT NULL OR TR_AO.ROUTID IS NOT NULL)\n" +
                "            AND (TR_AL.ORDERTYPE = 'AO' OR TR_AO.ORDERTYPE = 'AO')\n" +
                "\n" +
                "         UNION\n" +
                "         --大运\n" +
                "         SELECT ROW_NUMBER() OVER( PARTITION BY ms.ID order by MSRL.created_date DESC) AS R_NUM,   \n" +
                "                'DYERP'                AS datasource,\n" +
                "                MS.ID                  AS MES_ID,\n" +
                "                MS.FO_NO               AS FO_NO,\n" +
                "                'FO'                   AS ROUTE_TYPE,\n" +
                "                TR_F.Routid            AS Routid,\n" +
                "                TR_F.PRTNO             AS PRTNO,\n" +
                "                TR_F.ROUTNO            AS ROUTNO,\n" +
                "                TR_F.PRTMDEPT          AS PRTMDEPT,\n" +
                "                MS.created_date        AS MES_CREATION_DATE\n" +
                "           FROM XAC_ERP.ODS_NEWERP_MES_SO MS\n" +
                "     INNER JOIN XAC_ERP.ODS_NEWERP_MDS_ITEM MI ON MI.ID = MS.MDS_ITEM_ID\n" +
                "      LEFT JOIN xac_erp.ODS_NEWERP_mes_so_print_record MSRL ON MSRL.so_id = MS.ID\n" +
                "      LEFT JOIN xac_erp.ODS_NEWERP_T_ROUTVERSION TR_F ON TR_F.ROUTID = MSRL.LEANMES_ROUTID\n" +
                "          WHERE TR_F.ROUTID IS NOT NULL\n" +
                "            AND TR_F.ORDERTYPE = 'FO' \n" +
                "         UNION\n" +
                "         SELECT ROW_NUMBER() OVER(PARTITION BY MS.ID,TR_AL.PRTNO,TR_AO.PRTNO order by MSRL.created_date DESC) AS R_NUM,\n" +
                "                'DYERP'                                  AS datasource,\n" +
                "                MS.ID                                    AS MES_ID,\n" +
                "                MS.FO_NO                                 AS FO_NO,\n" +
                "                'AO'                                     AS ROUTE_TYPE,\n" +
                "                coalesce(TR_AL.Routid, TR_AO.Routid)     AS Routid,\n" +
                "                coalesce(TR_AL.PRTNO, TR_AO.PRTNO)       AS PRTNO,\n" +
                "                coalesce(TR_AL.ROUTNO, TR_AO.ROUTNO)     AS ROUTNO,\n" +
                "                coalesce(TR_AL.PRTMDEPT, TR_AO.PRTMDEPT) AS PRTMDEPT,\n" +
                "                MS.created_date                          AS MES_CREATION_DATE\n" +
                "           FROM XAC_ERP.ODS_NEWERP_MES_SO MS\n" +
                "     INNER JOIN XAC_ERP.ODS_NEWERP_MDS_ITEM MI ON MI.ID = MS.MDS_ITEM_ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_NEWERP_mes_so_print_record MSRL ON MSRL.so_id = MS.ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_NEWERP_T_AOLIST AO_L ON AO_L.ID = MSRL.LEANMES_ROUTID\n" +
                "      LEFT JOIN XAC_ERP.ODS_NEWERP_T_AOLISTITEM AO_LI ON AO_LI.AOLISTID = AO_L.ID\n" +
                "      LEFT JOIN XAC_ERP.ODS_NEWERP_T_ROUTVERSION TR_AL ON TR_AL.ROUTID = AO_LI.ROUTID\n" +
                "      LEFT JOIN XAC_ERP.ODS_NEWERP_T_ROUTVERSION TR_AO ON TR_AO.ROUTID = MSRL.LEANMES_ROUTID\n" +
                "          WHERE (TR_AL.ROUTID IS NOT NULL OR TR_AO.ROUTID IS NOT NULL)\n" +
                "            AND (TR_AL.ORDERTYPE = 'AO' OR TR_AO.ORDERTYPE = 'AO')\n" +
                "),\n" +
                "MES_ROUTE_INFO AS \n" +
                "(      --基于整理的指令进行聚合，准备判断所需的条件\n" +
                "        SELECT MRR.MES_ID,\n" +
                "               MRR.datasource,\n" +
                "               COUNT(DISTINCT MRR.FO_NO) AS FO_NO_C,\n" +
                "               SUM( CASE WHEN MRR.ROUTE_TYPE = 'AO' AND MRR.PRTNO IS NOT NULL THEN 1 ELSE 0 END ) AS AO_NUM,\n" +
                "               SUM( CASE WHEN MRR.ROUTE_TYPE = 'FO' AND MRR.PRTNO IS NOT NULL THEN 1 ELSE 0 END ) AS FO_NUM\n" +
                "          FROM MES_RELEASE_ROUTE MRR\n" +
                "      GROUP BY MRR.datasource, MRR.MES_ID\n" +
                "),\n" +
                "MES_ROUTE_VALID AS \n" +
                "(       --标识指令份数有效的标识\n" +
                "        SELECT MRI.MES_ID,\n" +
                "               MRI.datasource, \n" +
                "               CASE WHEN FO_NUM = 1 AND AO_NUM = 0 \n" +
                "                      OR FO_NUM = 0 AND AO_NUM > 0 AND FO_NO_C = 1\n" +
                "                      OR FO_NUM > 1 AND AO_NUM = 0 AND FO_NO_C = 1 \n" +
                "                    THEN 1 ELSE 0 END FLAG_OK\n" +
                "          FROM MES_ROUTE_INFO MRI\n" +
                "),\n" +
                "MES_ROUTE_OK AS \n" +
                "(\n" +
                "        --基于MES_SO提供有效的指令（含已将父FO_NO去重）：2133070\n" +
                "        SELECT MRR.datasource AS datasource,\n" +
                "               MRR.MES_ID     AS MES_ID,\n" +
                "               MRR.ROUTE_TYPE AS ITEM_CLASS,\n" +
                "               MRR.Routid     AS Routid,\n" +
                "               MRR.PRTNO      AS PRTNO,\n" +
                "               MRR.ROUTNO     AS ROUTNO,\n" +
                "               MRR.PRTMDEPT   AS PRTMDEPT\n" +
                "          FROM MES_RELEASE_ROUTE MRR\n" +
                "     LEFT JOIN MES_ROUTE_VALID MRV ON MRV.MES_ID = MRR.MES_ID and MRV.datasource = MRR.datasource\n" +
                "         WHERE MRV.FLAG_OK = 1\n" +
                "           AND MRR.R_NUM = 1\n" +
                ")\n" +
                "INSERT overwrite table xactest.COST_MESSO_ITEM_ROUTE\n" +
                "      -----1、零件计划--------------------------------------------------------------------------------------------------\n" +
                "      SELECT 'JJERP'                        AS date_source,         --date_source\n" +
                "             max(CASE WHEN MRO.ITEM_CLASS = 'FO' THEN 'LJ'\n" +
                "                      WHEN MRO.ITEM_CLASS = 'AO' THEN 'ZJ'\n" +
                "                      ELSE NULL END)        AS ITEM_TYPE_JS,        --计算的零部组件类型\n" +
                "             mewo.ID                        AS MERP_EWO_ID,         --mes_ewo_id\n" +
                "             max(mewo.ewo_no)               AS MERP_EWO_NO,         --mes_ewo_no\n" +
                "             max(MS.DEPT_ORDER)             AS MS_DEPTORDER,        --ms.deptorder\n" +
                "             MAX(MS.ID)                     AS MS_ID,               --MS_ID\n" +
                "             max(ms.so_no)                  AS MS_SONO,             --ms.sono\n" +
                "             max(ms.FO_NO)                  AS MS_FONO,             --ms.fono\n" +
                "             ----------------------------------------------------------------------\n" +
                "             max(mewo.Creation_Date)        AS PLAN_Creation_Date,  --计划下达时间\n" +
                "             max(MIP.ITEM_CODE)             AS PLAN_CODE,           --机型\n" +
                "             max(MIP.ID)                    AS PLAN_CODE_ID,        --机型ID\n" +
                "             max(mewo.manufacture_lotno)    AS LOT,                 --架次区间\n" +
                "             max(substr(mewo.manufacture_lotno,instr(mewo.manufacture_lotno, '-') + 1)) AS MAX_LOT,--最大架次\n" +
                "             max(mi.item_code)              AS ITEM_CODE,           --零部组件号\n" +
                "             MAX(MI.ID)                     AS ITEM_CODE_ID,        --零部组件号ID\n" +
                "             max(mi.item_name)              AS ITEM_NAME,           --零部组件名称\n" +
                "             max(mi.item_type)              AS ITEM_TYPE,           --零部组件类型\n" +
                "             max(MS.WORK_LINE)              AS MS_WORKLINE,         --分工路线(原)                                       \n" +
                "             --不论是主制还是首车间，只需要只截取部门，但要注意指令编制部门和对应的路线部门可能不是一个，因为发放单位不一定是编制单位                        \n" +
                "             MAX(case when MS.DEPT_ORDER = 1 AND SIZE(SPLIT(MS.WORK_LINE, '-')) = 2 then 1     --首车间+主制\n" +
                "                      when MS.DEPT_ORDER = 1 AND SIZE(SPLIT(MS.WORK_LINE, '-')) > 2 then 2     --首车间\n" +
                "                      when MS.DEPT_ORDER > 1 AND INSTR(MS.WORK_LINE, HDM.DEPT_CODE) = 1 then 2 --路线首车间发放指令，但车间顺序号不是1，也是首车间\n" +
                "                      WHEN MS.DEPT_ORDER > 1 AND INSTR(MS.WORK_LINE, HDM.DEPT_CODE) > 1 THEN 3 --主制\n" +
                "                     else null end )        AS DEPT_CLASS,          --部门类型：1首车间+主制2首车间3主制部门\n" +
                "             MAX(HDM.DEPT_CODE)             AS MESSO_DEPT,          --计划路线部门(原)\n" +
                "             MAX(MRO.prtmdept)              AS ROUTE_prtmdept,      --指令部门(原)\n" +
                "             MAX(coalesce(MDR_O.OLD_DEPT_CODE, HDM.DEPT_CODE))   AS MESSO_DEPT_O,--路线部门(旧)             \n" +
                "             MAX(coalesce(MDR_M.NEW_DEPT_CODE, HDM.DEPT_CODE))   AS MESSO_DEPT_N,--路线部门(新)\n" +
                "             MAX(coalesce(MDR_V.NEW_DEPT_CODE, MRO.prtmdept))    AS ROUTE_DEPT_N,--指令部门（新）\n" +
                "             MAX(MRO.ROUTID)                AS ROUTEVERSION_ID,     --对应指令ID\n" +
                "             MAX(MRO.PRTNO)                 AS TR_PRTNO,            --指令编号\n" +
                "             MAX(MRO.ROUTNO)                AS TR_ROUTNO            --指令版本\n" +
                "        FROM xac_erp.ODS_JJERP_MES_EWO mewo\n" +
                "  INNER JOIN xac_erp.ODS_JJERP_MDS_ITEM MIP ON MIP.ID = MEWO.PRO_MDS_ITEM_ID\n" +
                "  INNER JOIN xac_erp.ODS_JJERP_MDS_ITEM MI ON MI.ID = MEWO.MDS_ITEM_ID\n" +
                "   LEFT JOIN xac_erp.ODS_JJERP_MES_SO ms on ms.mes_ewo_id = mewo.id --关联有效指令\n" +
                "  INNER JOIN MES_ROUTE_OK MRO ON MRO.MES_ID = MS.ID AND MRO.datasource = 'JJERP'\n" +
                "   LEFT JOIN xac_erp.ODS_JJERP_HR_DEPT HDM ON HDM.ID = MS.MANUFACT_HR_DEPT_ID\n" +
                "   LEFT JOIN xac_erp.ODS_JJERP_MDS_DEPT_RELATION MDR_M ON MDR_M.OLD_DEPT_CODE = HDM.DEPT_CODE\n" +
                "   LEFT JOIN xac_erp.ODS_JJERP_MDS_DEPT_RELATION MDR_V ON MDR_V.OLD_DEPT_CODE = MRO.prtmdept\n" +
                "   LEFT JOIN xac_erp.ODS_JJERP_MDS_DEPT_RELATION MDR_O ON MDR_O.NEW_DEPT_CODE = HDM.DEPT_CODE   \n" +
                "       WHERE mewo.Wo_Type = '1' --批次计划\n" +
                "         AND mewo.Creation_Date >= date_sub(current_date, 1000)\n" +
                "    GROUP BY mewo.ID,MRO.ROUTID\n" +
                "\n" +
                "UNION\n" +
                "\n" +
                "      SELECT\n" +
                "             'MJERP'                        AS date_source,         --date_source\n" +
                "             max(CASE WHEN MRO.ITEM_CLASS = 'FO' THEN 'LJ'\n" +
                "                      WHEN MRO.ITEM_CLASS = 'AO' THEN 'ZJ'\n" +
                "                      ELSE NULL END)        AS ITEM_TYPE_JS,        --计算的零部组件类型\n" +
                "             mewo.ID                        AS MERP_EWO_ID,         --mes_ewo_id\n" +
                "             max(mewo.ewo_no)               AS MERP_EWO_NO,         --mes_ewo_no\n" +
                "             max(MS.DEPT_ORDER)             AS MS_DEPTORDER,        --ms.deptorder\n" +
                "             MAX(MS.ID)                     AS MS_ID,               --MS_ID\n" +
                "             max(ms.so_no)                  AS MS_SONO,             --ms.sono\n" +
                "             max(ms.FO_NO)                  AS MS_FONO,             --ms.fono\n" +
                "             ----------------------------------------------------------------------\n" +
                "             max(mewo.Creation_Date)        AS PLAN_Creation_Date,  --计划下达时间\n" +
                "             max(MIP.ITEM_CODE)             AS PLAN_CODE,           --机型\n" +
                "             max(MIP.ID)                    AS PLAN_CODE_ID,        --机型ID\n" +
                "             max(mewo.manufacture_lotno)    AS LOT,                 --架次区间\n" +
                "             max(substr(mewo.manufacture_lotno,instr(mewo.manufacture_lotno, '-') + 1)) AS MAX_LOT,--最大架次\n" +
                "             max(mi.item_code)              AS ITEM_CODE,           --零部组件号\n" +
                "             MAX(MI.ID)                     AS ITEM_CODE_ID,        --零部组件号ID\n" +
                "             max(mi.item_name)              AS ITEM_NAME,           --零部组件名称\n" +
                "             max(mi.item_type)              AS ITEM_TYPE,           --零部组件类型\n" +
                "             max(MS.WORK_LINE)              AS MS_WORKLINE,         --分工路线(原)                                       \n" +
                "             --不论是主制还是首车间，只需要只截取部门，但要注意指令编制部门和对应的路线部门可能不是一个，因为发放单位不一定是编制单位                        \n" +
                "             MAX(case when MS.DEPT_ORDER = 1 AND SIZE(SPLIT(MS.WORK_LINE, '-')) = 2 then 1     --首车间+主制\n" +
                "                      when MS.DEPT_ORDER = 1 AND SIZE(SPLIT(MS.WORK_LINE, '-')) > 2 then 2     --首车间\n" +
                "                      when MS.DEPT_ORDER > 1 AND INSTR(MS.WORK_LINE, HDM.DEPT_CODE) = 1 then 2 --路线首车间发放指令，但车间顺序号不是1，也是首车间\n" +
                "                      WHEN MS.DEPT_ORDER > 1 AND INSTR(MS.WORK_LINE, HDM.DEPT_CODE) > 1 THEN 3 --主制\n" +
                "                     else null end )        AS DEPT_CLASS,          --部门类型：1首车间+主制2首车间3主制部门\n" +
                "             MAX(HDM.DEPT_CODE)             AS MESSO_DEPT,          --计划路线部门(原)\n" +
                "             MAX(MRO.prtmdept)              AS ROUTE_prtmdept,      --指令部门(原)\n" +
                "             MAX(coalesce(MDR_O.OLD_DEPT_CODE, HDM.DEPT_CODE))   AS MESSO_DEPT_O,--路线部门(旧)              \n" +
                "             MAX(coalesce(MDR_M.NEW_DEPT_CODE, HDM.DEPT_CODE))   AS MESSO_DEPT_N,--路线部门(新)\n" +
                "             MAX(coalesce(MDR_V.NEW_DEPT_CODE, MRO.prtmdept))    AS ROUTE_DEPT_N,--指令部门（新）\n" +
                "             MAX(MRO.ROUTID)                AS ROUTEVERSION_ID,     --对应指令ID\n" +
                "             MAX(MRO.PRTNO)                 AS TR_PRTNO,            --指令编号\n" +
                "             MAX(MRO.ROUTNO)                AS TR_ROUTNO            --指令版本\n" +
                "        FROM xac_erp.ODS_MJERP_MES_EWO mewo\n" +
                "  INNER JOIN xac_erp.ODS_MJERP_MDS_ITEM MIP ON MIP.ID = MEWO.PRO_MDS_ITEM_ID\n" +
                "  INNER JOIN xac_erp.ODS_MJERP_MDS_ITEM MI ON MI.ID = MEWO.MDS_ITEM_ID\n" +
                "   LEFT JOIN xac_erp.ODS_MJERP_MES_SO ms on ms.mes_ewo_id = mewo.id \n" +
                "   --关联有效指令\n" +
                "  INNER JOIN MES_ROUTE_OK MRO ON MRO.MES_ID = MS.ID AND MRO.datasource = 'MJERP'\n" +
                "   LEFT JOIN xac_erp.ODS_MJERP_HR_DEPT HDM ON HDM.ID = MS.MANUFACT_HR_DEPT_ID\n" +
                "   LEFT JOIN xac_erp.ODS_MJERP_MDS_DEPT_RELATION MDR_M ON MDR_M.OLD_DEPT_CODE = HDM.DEPT_CODE\n" +
                "   LEFT JOIN xac_erp.ODS_MJERP_MDS_DEPT_RELATION MDR_V ON MDR_V.OLD_DEPT_CODE = MRO.prtmdept\n" +
                "   LEFT JOIN xac_erp.ODS_MJERP_MDS_DEPT_RELATION MDR_O ON MDR_O.NEW_DEPT_CODE = HDM.DEPT_CODE      \n" +
                "       WHERE mewo.Wo_Type = '1' --批次计划\n" +
                "         AND mewo.Creation_Date >= date_sub(current_date, 1000)\n" +
                "    GROUP BY mewo.ID,MRO.ROUTID\n" +
                "\n" +
                "UNION\n" +
                "\n" +
                "      SELECT 'DYERP'                        AS date_source,         --date_source\n" +
                "             max(CASE WHEN MRO.ITEM_CLASS = 'FO' THEN 'LJ'\n" +
                "                      WHEN MRO.ITEM_CLASS = 'AO' THEN 'ZJ'\n" +
                "                      ELSE NULL END)        AS ITEM_TYPE_JS,        --计算的零部组件类型\n" +
                "             mewo.ID                        AS MERP_EWO_ID,         --mes_ewo_id\n" +
                "             max(mewo.ewo_no)               AS MERP_EWO_NO,         --mes_ewo_no\n" +
                "             max(MS.DEPT_ORDER)             AS MS_DEPTORDER,        --ms.deptorder\n" +
                "             MAX(MS.ID)                     AS MS_ID,               --MS_ID\n" +
                "             max(ms.so_no)                  AS MS_SONO,             --ms.sono\n" +
                "             max(ms.FO_NO)                  AS MS_FONO,             --ms.fono\n" +
                "             ----------------------------------------------------------------------\n" +
                "             max(mewo.Created_Date)         AS PLAN_Creation_Date,\n" +
                "             max(MIP.ITEM_CODE)             AS PLAN_CODE,           --机型\n" +
                "             max(MIP.ID)                    AS PLAN_CODE_ID,        --机型ID\n" +
                "             max(mewo.manufacture_lotno)    AS LOT,                 --架次区间\n" +
                "             max(substr(mewo.manufacture_lotno,instr(mewo.manufacture_lotno, '-') + 1)) AS MAX_LOT,--最大架次\n" +
                "             max(mi.item_code)              AS ITEM_CODE,           --零部组件号\n" +
                "             MAX(MI.ID)                     AS ITEM_CODE_ID,        --零部组件号ID\n" +
                "             max(mi.item_name)              AS ITEM_NAME,           --零部组件名称\n" +
                "             max(mi.item_type)              AS ITEM_TYPE,           --零部组件类型\n" +
                "             max(MS.WORK_LINE)              AS MS_WORKLINE,         --分工路线(原)                                       \n" +
                "             --不论是主制还是首车间，只需要只截取部门，但要注意指令编制部门和对应的路线部门可能不是一个，因为发放单位不一定是编制单位                        \n" +
                "             MAX(case when MS.DEPT_ORDER = 1 AND SIZE(SPLIT(MS.WORK_LINE, '-')) = 2 then 1     --首车间+主制\n" +
                "                      when MS.DEPT_ORDER = 1 AND SIZE(SPLIT(MS.WORK_LINE, '-')) > 2 then 2     --首车间\n" +
                "                      when MS.DEPT_ORDER > 1 AND INSTR(MS.WORK_LINE, HDM.DEPT_CODE) = 1 then 2 --路线首车间发放指令，但车间顺序号不是1，也是首车间\n" +
                "                      WHEN MS.DEPT_ORDER > 1 AND INSTR(MS.WORK_LINE, HDM.DEPT_CODE) > 1 THEN 3 --主制\n" +
                "                     else null end )        AS DEPT_CLASS,          --部门类型：1首车间+主制2首车间3主制部门\n" +
                "             MAX(HDM.DEPT_CODE)             AS MESSO_DEPT,          --计划路线部门(原)\n" +
                "             MAX(MRO.prtmdept)              AS ROUTE_prtmdept,      --指令部门(原)\n" +
                "             MAX(coalesce(MDR_O.OLD_DEPT_CODE, HDM.DEPT_CODE))   AS MESSO_DEPT_O,--路线部门(旧)               \n" +
                "             MAX(coalesce(MDR_M.NEW_DEPT_CODE, HDM.DEPT_CODE))   AS MESSO_DEPT_N,--路线部门(新)\n" +
                "             MAX(coalesce(MDR_V.NEW_DEPT_CODE, MRO.prtmdept))    AS ROUTE_DEPT_N,--指令部门（新）\n" +
                "             MAX(MRO.ROUTID)                AS ROUTEVERSION_ID,     --对应指令ID\n" +
                "             MAX(MRO.PRTNO)                 AS TR_PRTNO,            --指令编号\n" +
                "             MAX(MRO.ROUTNO)                AS TR_ROUTNO            --指令版本\n" +
                "        FROM xac_erp.ODS_NEWERP_MES_EWO mewo\n" +
                "  INNER JOIN xac_erp.ODS_NEWERP_MDS_ITEM MIP ON MIP.ID = MEWO.PRO_MDS_ITEM_ID\n" +
                "  INNER JOIN xac_erp.ODS_NEWERP_MDS_ITEM MI ON MI.ID = MEWO.MDS_ITEM_ID\n" +
                "   LEFT JOIN xac_erp.ODS_NEWERP_MES_SO ms on ms.mes_ewo_id = mewo.id --关联有效指令\n" +
                "  INNER JOIN MES_ROUTE_OK MRO ON MRO.MES_ID = MS.ID AND MRO.datasource = 'DYERP'\n" +
                "   LEFT JOIN xac_erp.ODS_NEWERP_Org_Dept HDM ON HDM.Dept_Key = MS.MANUFACT_HR_DEPT_ID\n" +
                "   LEFT JOIN xac_erp.ODS_NEWERP_MDS_DEPT_RELATION MDR_M ON MDR_M.OLD_DEPT_CODE = HDM.DEPT_CODE\n" +
                "   LEFT JOIN xac_erp.ODS_NEWERP_MDS_DEPT_RELATION MDR_V ON MDR_V.OLD_DEPT_CODE = MRO.prtmdept\n" +
                "   LEFT JOIN xac_erp.ODS_NEWERP_MDS_DEPT_RELATION MDR_O ON MDR_O.NEW_DEPT_CODE = HDM.DEPT_CODE      \n" +
                "       WHERE mewo.Wo_Type = '1' --批次计划\n" +
                "         AND mewo.Created_Date >= date_sub(current_date, 1000)\n" +
                "    GROUP BY mewo.ID,MRO.ROUTID\n" +
                "\n" +
                "    union\n" +
                "  \n" +
                "   -----2、装配计划------------------------------------------------------------------------------------------   \n" +
                "         SELECT 'DYERP'                        AS date_source,          --date_source\n" +
                "                'BJ'                           AS ITEM_TYPE_JS,         --计算的零部组件类型          \n" +
                "                MW.ID                          AS MERP_EWO_ID,          --装配计划MRP_WO_ID\n" +
                "                MW.WO_NO                       AS MERP_EWO_NO,          --装配计划MRP_WONO\n" +
                "                0                              AS MS_DEPTORDER,         --ms.deptorder\n" +
                "                NULL                           AS MS_ID,                --MS_ID            \n" +
                "                NULL                           AS MS_SONO,              --ms.sono\n" +
                "                NULL                           AS MS_FONO,              --ms.fono                \n" +
                "                MW.created_date                AS PLAN_Creation_Date,   --计划下达时间,\n" +
                "                MI_P.ITEM_CODE                 AS PLAN_CODE,            --机型\n" +
                "                MW.PRO_MDS_ITEM_ID             AS PLAN_CODE_ID,         --机型ID,\n" +
                "                MW.MANUFACTURE_LOTNO           AS LOT,                  --架次区间\n" +
                "                NULL                           AS MAX_LOT,              --最大架次,\n" +
                "                MI.ITEM_CODE                   AS ITEM_CODE,            --零部组件号,\n" +
                "                MW.MDS_ITEM_ID                 AS ITEM_CODE_ID,         --零部组件号ID   ,\n" +
                "                MI.ITEM_NAME                   AS ITEM_NAME,            --零部组件名称\n" +
                "                MI.ITEM_TYPE                   AS ITEM_TYPE,            --零部组件类型\n" +
                "                NULL                           AS MS_WORKLINE,          --分工路线(原) \n" +
                "                1                              AS DEPT_CLASS,           --部门类型：1首车间+主制2首车间3主制部门\n" +
                "                HDM.DEPT_CODE                  AS MESSO_DEPT,           --计划路线部门(原)  \n" +
                "                NULL                           AS ROUTE_prtmdept,       --指令部门(原)     \n" +
                "                coalesce(MDR_O.OLD_DEPT_CODE, HDM.DEPT_CODE)  AS MESSO_DEPT_O,  --路线部门(旧)                                         \n" +
                "                coalesce(MDR_M.NEW_DEPT_CODE,HDM.DEPT_CODE)   AS MESSO_DEPT_N,  --路线部门(新)\n" +
                "                NULL                           AS ROUTE_DEPT_N,         --指令部门（新）\n" +
                "                TR.ROUTID                      AS ROUTEVERSION_ID,      --对应指令ID,\n" +
                "                TR.PRTNO                       AS TR_PRTNO,             --指令编号\n" +
                "                TR.ROUTNO                      AS TR_ROUTNO             --指令版本                                                  \n" +
                "           FROM xac_erp.ODS_NEWERP_MRP_WO MW_AO   \n" +
                "     INNER JOIN xac_erp.ODS_NEWERP_T_ROUTMES TRM ON TRM.SONO=MW_AO.WO_NO\n" +
                "     INNER JOIN xac_erp.ODS_DYERP_LEANMESDY_T_ROUTVERSION TR ON TR.ROUTID=TRM.ROUTID\n" +
                "     INNER JOIN xac_erp.ODS_NEWERP_MRP_WO MW ON MW.Id= MW_AO.Parent_Wo_Id    \n" +
                "     INNER JOIN xac_erp.ODS_NEWERP_MDS_ITEM MI_P ON MI_P.ID=MW.PRO_MDS_ITEM_ID\n" +
                "     INNER JOIN xac_erp.ODS_NEWERP_MDS_ITEM MI ON MI.ID=MW.Mds_Item_Id       \n" +
                "      LEFT JOIN xac_erp.ODS_NEWERP_Org_Dept HDM ON HDM.Dept_Key=MW.MANUFACT_HR_DEPT_ID \n" +
                "      LEFT JOIN xac_erp.ODS_NEWERP_MDS_DEPT_RELATION MDR_M ON  MDR_M.OLD_DEPT_CODE=HDM.DEPT_CODE   \n" +
                "      LEFT JOIN xac_erp.ODS_NEWERP_MDS_DEPT_RELATION MDR_O ON MDR_O.NEW_DEPT_CODE = HDM.DEPT_CODE                                  \n" +
                "          WHERE MW.WO_TYPE=1\n" +
                "            AND MW.Created_Date >= date_sub(current_date,1000)            \n" +
                "   \n" +
                "   UNION\n" +
                "   \n" +
                "         SELECT 'JJERP'                        AS date_source,          --date_source\n" +
                "                'BJ'                           AS ITEM_TYPE_JS,         --计算的零部组件类型          \n" +
                "                MW.ID                          AS MERP_EWO_ID,          --装配计划MRP_WO_ID\n" +
                "                MW.WO_NO                       AS MERP_EWO_NO,          --装配计划MRP_WONO\n" +
                "                0                              AS MS_DEPTORDER,         --ms.deptorder\n" +
                "                NULL                           AS MS_ID,                --MS_ID            \n" +
                "                NULL                           AS MS_SONO,              --ms.sono\n" +
                "                NULL                           AS MS_FONO,              --ms.fono                \n" +
                "                MW.creation_date               AS PLAN_Creation_Date,   --计划下达时间,\n" +
                "                MI_P.ITEM_CODE                 AS PLAN_CODE,            --机型\n" +
                "                MW.PRO_MDS_ITEM_ID             AS PLAN_CODE_ID,         --机型ID,\n" +
                "                MW.MANUFACTURE_LOTNO           AS LOT,                  --架次区间\n" +
                "                NULL                           AS MAX_LOT,              --最大架次,\n" +
                "                MI.ITEM_CODE                   AS ITEM_CODE,            --零部组件号,\n" +
                "                MW.MDS_ITEM_ID                 AS ITEM_CODE_ID,         --零部组件号ID   ,\n" +
                "                MI.ITEM_NAME                   AS ITEM_NAME,            --零部组件名称\n" +
                "                MI.ITEM_TYPE                   AS ITEM_TYPE,            --零部组件类型\n" +
                "                NULL                           AS MS_WORKLINE,          --分工路线(原) \n" +
                "                1                              AS DEPT_CLASS,           --部门类型：1首车间+主制2首车间3主制部门\n" +
                "                HDM.DEPT_CODE                  AS MESSO_DEPT,           --计划路线部门(原)  \n" +
                "                NULL                           AS ROUTE_prtmdept,       --指令部门(原)     \n" +
                "                coalesce(MDR_O.OLD_DEPT_CODE, HDM.DEPT_CODE)  AS MESSO_DEPT_O,  --路线部门(旧)                                        \n" +
                "                coalesce(MDR_M.NEW_DEPT_CODE,HDM.DEPT_CODE)   AS MESSO_DEPT_N,  --路线部门(新)\n" +
                "                NULL                           AS ROUTE_DEPT_N,         --指令部门（新）\n" +
                "                TR.ROUTID                      AS ROUTEVERSION_ID,      --对应指令ID,\n" +
                "                TR.PRTNO                       AS TR_PRTNO,             --指令编号\n" +
                "                TR.ROUTNO                      AS TR_ROUTNO             --指令版本\n" +
                "           FROM xac_erp.ODS_JJERP_MRP_WO MW_AO   \n" +
                "     INNER JOIN xac_erp.ODS_JJERP_T_ROUTMES TRM ON TRM.SONO=MW_AO.WO_NO\n" +
                "     INNER JOIN xac_erp.ODS_JJERP_LEANMESDY_T_ROUTVERSION TR ON TR.ROUTID=TRM.ROUTID\n" +
                "     INNER JOIN xac_erp.ODS_JJERP_MRP_WO MW ON MW.Id= MW_AO.Parent_Wo_Id    \n" +
                "     INNER JOIN xac_erp.ODS_JJERP_MDS_ITEM MI_P ON MI_P.ID=MW.PRO_MDS_ITEM_ID\n" +
                "     INNER JOIN xac_erp.ODS_JJERP_MDS_ITEM MI ON MI.ID=MW.Mds_Item_Id       \n" +
                "      LEFT JOIN xac_erp.ODS_JJERP_HR_DEPT HDM ON HDM.ID=MW.MANUFACT_HR_DEPT_ID      \n" +
                "      LEFT JOIN xac_erp.ODS_JJERP_MDS_DEPT_RELATION MDR_M ON MDR_M.OLD_DEPT_CODE=HDM.DEPT_CODE                              \n" +
                "      LEFT JOIN xac_erp.ODS_JJERP_MDS_DEPT_RELATION MDR_O ON MDR_O.NEW_DEPT_CODE = HDM.DEPT_CODE         \n" +
                "          WHERE MW.WO_TYPE=1\n" +
                "            AND MW.creation_date >= date_sub(current_date,1000)          \n" +
                "   \n" +
                "   UNION\n" +
                "  \n" +
                "        SELECT   'MJERP'                        AS date_source,          --date_source\n" +
                "                 'BJ'                           AS ITEM_TYPE_JS,         --计算的零部组件类型          \n" +
                "                 MW.ID                          AS MERP_EWO_ID,          --装配计划MRP_WO_ID\n" +
                "                 MW.WO_NO                       AS MERP_EWO_NO,          --装配计划MRP_WONO\n" +
                "                 0                              AS MS_DEPTORDER,         --ms.deptorder\n" +
                "                 NULL                           AS MS_ID,                --MS_ID            \n" +
                "                 NULL                           AS MS_SONO,              --ms.sono\n" +
                "                 NULL                           AS MS_FONO,              --ms.fono                \n" +
                "                 MW.creation_date               AS PLAN_Creation_Date,   --计划下达时间,\n" +
                "                 MI_P.ITEM_CODE                 AS PLAN_CODE,            --机型\n" +
                "                 MW.PRO_MDS_ITEM_ID             AS PLAN_CODE_ID,         --机型ID,\n" +
                "                 MW.MANUFACTURE_LOTNO           AS LOT,                  --架次区间\n" +
                "                 NULL                           AS MAX_LOT,              --最大架次,\n" +
                "                 MI.ITEM_CODE                   AS ITEM_CODE,            --零部组件号,\n" +
                "                 MW.MDS_ITEM_ID                 AS ITEM_CODE_ID,         --零部组件号ID   ,\n" +
                "                 MI.ITEM_NAME                   AS ITEM_NAME,            --零部组件名称\n" +
                "                 MI.ITEM_TYPE                   AS ITEM_TYPE,            --零部组件类型\n" +
                "                 NULL                           AS MS_WORKLINE,          --分工路线(原) \n" +
                "                 1                              AS DEPT_CLASS,           --部门类型：1首车间+主制2首车间3主制部门\n" +
                "                 HDM.DEPT_CODE                  AS MESSO_DEPT,           --计划路线部门(原)  \n" +
                "                 NULL                           AS ROUTE_prtmdept,       --指令部门(原)   \n" +
                "                 coalesce(MDR_O.OLD_DEPT_CODE, HDM.DEPT_CODE)  AS MESSO_DEPT_O,  --路线部门(旧)                             \n" +
                "                 coalesce(MDR_M.NEW_DEPT_CODE,HDM.DEPT_CODE)   AS MESSO_DEPT_N,  --路线部门(新)\n" +
                "                 NULL                           AS ROUTE_DEPT_N,         --指令部门（新）\n" +
                "                 TR.ROUTID                      AS ROUTEVERSION_ID,     --对应指令ID,\n" +
                "                 TR.PRTNO                       AS TR_PRTNO,            --指令编号\n" +
                "                 TR.ROUTNO                      AS TR_ROUTNO            --指令版本                                                 \n" +
                "            FROM xac_erp.ODS_MJERP_MRP_WO MW_AO   \n" +
                "      INNER JOIN xac_erp.ODS_MJERP_T_ROUTMES TRM ON TRM.SONO=MW_AO.WO_NO\n" +
                "      INNER JOIN xac_erp.ODS_MJERP_LEANMESDY_T_ROUTVERSION TR ON TR.ROUTID=TRM.ROUTID\n" +
                "      INNER JOIN xac_erp.ODS_MJERP_MRP_WO MW ON MW.Id= MW_AO.Parent_Wo_Id    \n" +
                "      INNER JOIN xac_erp.ODS_MJERP_MDS_ITEM MI_P ON MI_P.ID=MW.PRO_MDS_ITEM_ID\n" +
                "      INNER JOIN xac_erp.ODS_MJERP_MDS_ITEM MI ON MI.ID=MW.Mds_Item_Id       \n" +
                "       LEFT JOIN xac_erp.ODS_MJERP_HR_DEPT HDM ON HDM.ID=MW.MANUFACT_HR_DEPT_ID      \n" +
                "       LEFT JOIN xac_erp.ODS_MJERP_MDS_DEPT_RELATION MDR_M ON MDR_M.OLD_DEPT_CODE=HDM.DEPT_CODE                              \n" +
                "       LEFT JOIN xac_erp.ODS_MJERP_MDS_DEPT_RELATION MDR_O ON MDR_O.NEW_DEPT_CODE = HDM.DEPT_CODE       \n" +
                "           WHERE MW.WO_TYPE=1\n" +
                "             AND MW.creation_date >= date_sub(current_date,1000)              \n" +
                ";\n" +
                "\n" +
                "\n" +
                "  SELECT Date_source,ITEM_TYPE_JS,count(*)\n" +
                "    FROM xactest.COST_MESSO_ITEM_ROUTE\n" +
                "GROUP BY date_source,ITEM_TYPE_JS\n" +
                "order by date_source,ITEM_TYPE_JS;";
        List<DataLineageDto> parser = createParser(viewSql);
        System.out.println(parser);
    }
}
